package com.wn.class30.cotroller.houtai;

import com.wn.class30.service.UserAddressService;
import com.wn.class30.tools.Page;
import com.wn.class30.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class UserAddressController {
    @Resource
    private UserAddressService userAddressService;

    @RequiresPermissions("/houtai/page/user/address/list")
    @RequestMapping("/houtai/page/user/address/list")
    public Result backUserList() throws Exception {
        return new Result("200","success",null,null);
    }
    @RequestMapping("/houtai/user/getAddress")
    public Result getAddressByPage(Integer page,Integer limit,String name, String tel, String addr) throws Exception {
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf(page));
        map.put("limit",String.valueOf(limit) );
        map.put("name", name);
        map.put("tel", tel);
        map.put("addr", addr);
        Page pager = new Page();
        pager.setCurrentPage(page);
        pager.setPageSize(limit);
        int count = userAddressService.selectCount((HashMap) map);
        pager.setTotalSize(count);
        pager.setTotalPage(count%limit==0?count/limit:count/limit+1);
        return new Result("0","success",pager, (List) userAddressService.select((HashMap) map));

    }
}
